# Maintainer: Giancarlo Razzolini <grazzolini@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=tinyssh
pkgver=20230101
pkgrel=1
pkgdesc="Small SSH server using NaCl / TweetNaCl"
arch=(loong64 x86_64)
url="https://tinyssh.org"
license=('custom:CC0')
conflicts=(tinyssh-convert)
provides=(tinyssh-convert)
replaces=(tinyssh-convert)
depends=(glibc)
optdepends=('python: for tinyssh-convert/converting OpenSSH keys')
source=(https://github.com/janmojzis/${pkgname}/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz
        tinyssh@.socket tinyssh@.service tinysshgenkeys.service
        ${pkgname}-${pkgver}.tar.gz.asc::https://github.com/janmojzis/${pkgname}/releases/download/${pkgver}/${pkgver}.tar.gz.asc)
sha512sums=('6beaf266058a89a78c710abd1a02feff0641a93d0d92aa07a1ad1ba3f6b3344bc312bb5a4cd5c06c6dcc83d25e48a801f9cfcfbb3de0f73904f36d32d4430482'
            '9fbc5ae3b6d1df6d78eedf812fdd8fe115e81fc0811f4799d541e37239d53db22203e691026ed479a38c9f17043e52d43b44054be51ae03c2f12f3f235c5b83a'
            '9c9ba78c5b61f64f42f59cfe556519d9ab2c3e4d45f36d6f78c5e7728b050c494673239630dae66398006f3f20fb3a26f22899cd0728ed17e61c655b372236b3'
            '415cdfe649eedcbb11a263938c0a66bef42432210baa2e2c9e428d5e8e486fb4dedad53b9fdb9086bf97ca506909d3b3054aaca56f02c063e0b8d5fab4e56198'
            'SKIP')
validpgpkeys=(AADF2EDF5529F1702772C8A2DEC4D246931EF49B)

build () {
  cd ${pkgname}-${pkgver//./}
  make
}

package () {
  cd ${pkgname}-${pkgver//./}
  make install DESTDIR="${pkgdir}"

  # Nowadays /usr/sbin is a symlink to /usr/bin
  mv "${pkgdir}"/usr/{s,}bin

  # Multi-call binary
  ln -sf tinysshd "${pkgdir}"/usr/bin/tinysshd-makekey
  ln -sf tinysshd "${pkgdir}"/usr/bin/tinysshd-printkey

  # Converting tool
  install -m755 tools/tinyssh-convert -t "${pkgdir}"/usr/bin
  
  install -m755 -d "${pkgdir}"/etc/tinyssh

  install -Dm644 -t "${pkgdir}"/usr/lib/systemd/system \
      "${srcdir}"/tinysshgenkeys.service \
      "${srcdir}"/tinyssh@.service \
      "${srcdir}"/tinyssh@.socket

  install -Dm644 LICENCE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
